﻿//获取参数
function getQueryString(queryName){ 
     var reg = new RegExp("(^|&)"+ queryName +"=([^&]*)(&|$)"); 
     var r = window.location.search.substr(1).match(reg); 
     if (r!=null)
        return unescape(r[2]);
        
     return null; 
}
/*弹出窗口*/
var winDlg=null || window;
function openDlg(_id, _title, _page, _width, _height, _parentDlg, _callBack) {
    _id = _id.toLocaleLowerCase();
    _parentDlg = _parentDlg.toLocaleLowerCase();
    //alert(_id+"_"+_parentDlg);
    if(_parentDlg!='null' && _parentDlg!='' && _parentDlg!=null){
        var api = frameElement.api,W=api.opener;
        var pApi=api.get(_id,1);
        var arr = _page.split('?');
        if(arr[0]==_page)
            _page+="?parentDlg="+_parentDlg;
        else
            _page+="&parentDlg="+_parentDlg;
            
        winDlg=W.$.dialog({id:_id,title:_title,content: 'url:'+_page,width:_width,height:_height,lock:true,resize:false,fixed:true,min:false,max:false,parent:api,
               close:function(){
                    api.zindex(); 
                    api.content.close();
               }
        });
    }
    else
        winDlg=$.dialog({id:_id,title:_title,content: 'url:'+_page,width:_width,height:_height,resize:true,fixed:true,min:false,hidden:_callBack});
}
function openTips(_content){
    alert(_content);
}
//获取返回值(多个参数或值之间用“|”隔开)
function getValue(hidArg,txtArg,imgArg,hidValue,txtValue,imgValue,btnUniqueId){
    var api = frameElement.api, W = api.opener,D=W.document;
    var pApi=null,pW=null,pD=null;
    if(getQueryString("parentDlg")!=null && getQueryString("parentDlg")!='null' && getQueryString("parentDlg")!=''){
        pApi=api.get(getQueryString("parentDlg"),1);
        pW=pApi.content;
        pD=pW.document;
    }

    var ctlhids= new Array(); if(hidArg!=null && hidArg!='' && hidArg!=undefined && getQueryString(hidArg)!=null) ctlhids=getQueryString(hidArg).split('|'); 
    var ctltxts= new Array(); if(txtArg!=null && txtArg!='' && txtArg!=undefined && getQueryString(txtArg)!=null) ctltxts=getQueryString(txtArg).split('|');
    var ctlimgs= new Array(); if(imgArg!=null && imgArg!='' && imgArg!=undefined && getQueryString(imgArg)!=null) ctlimgs=getQueryString(imgArg).split('|');
    var ctlbtns= new Array(); if(btnUniqueId!=null && btnUniqueId!='' && btnUniqueId!=undefined && getQueryString(btnUniqueId)!=null) ctlbtns=getQueryString(btnUniqueId).split('|');
    
    if(ctlhids.length>0){
        var valhids= new Array();
        if(hidValue!=null && hidValue!='' && hidValue!=undefined) valhids=hidValue.split('|');
            
        for(var i=0;i<ctlhids.length;i++){
            hidArg=pApi!=null?pD.getElementById(ctlhids[i]):D.getElementById(ctlhids[i]);
            if(hidArg!=null && hidArg!='' && hidArg!=undefined && valhids[i]!=undefined)
                hidArg.value=valhids[i];
        }  
    }
    if(ctltxts.length>0){
        var valtxts= new Array();
        if(txtValue!=null && txtValue!='' && txtValue!=undefined) valtxts=txtValue.split('|');
            
        for(var i=0;i<ctltxts.length;i++){
            txtArg=pApi!=null?pD.getElementById(ctltxts[i]):D.getElementById(ctltxts[i]);
            if(txtArg!=null && txtArg!='' && txtArg!=undefined && valtxts[i]!=undefined)
                txtArg.value=valtxts[i];
        }
    }
    if(ctlimgs.length>0){
        var valimgs= new Array();
        if(imgValue!=null && imgValue!='' && imgValue!=undefined) valimgs=imgValue.split('|');

        for(var i=0;i<ctlimgs.length;i++){
            imgArg=pApi!=null?pD.getElementById(ctlimgs[i]):D.getElementById(ctlimgs[i]);
            if(imgArg!=null && imgArg!='' && imgArg!=undefined && valimgs[i]!=undefined)
                imgArg.src=valimgs[i];
        }
    }
    if(ctlbtns.length>0){
        for(var i=0;i<ctlbtns.length;i++)
            pApi!=null?pW.__doPostBack(ctlbtns[i],''):D.__doPostBack(ctlbtns[i],'');//.NET自动生成的提交事件   
    }   
    closeDlg();
}
//返回NET自动生成的提交事件,多个用"|"隔开
function DoPostBack(buttonId) {
    var api = frameElement.api, W = api.opener,D=W.document;
    var ctlbuttons= new Array(); if(buttonId!=null && buttonId!='' && buttonId!=undefined) ctlbuttons=buttonId.split('|'); 
    if(getQueryString("parentDlg")!=null && getQueryString("parentDlg")!='null' && getQueryString("parentDlg")!=''){
        var pApi=api.get(getQueryString("parentDlg"),1),pW=pApi.content;

        for(var i=0;i<ctlbuttons.length;i++)
            pW.__doPostBack(ctlbuttons[i],'');//.NET自动生成的提交事件
    }
    else
        for(var i=0;i<ctlbuttons.length;i++)
            W.__doPostBack(ctlbuttons[i],'');//.NET自动生成的提交事件
}
//关闭
function closeDlg(){
    var api = frameElement.api;
    if (getQueryString("parentDlg") != null && getQueryString("parentDlg") != 'null' && getQueryString("parentDlg") != '') {
        var pApi = api.get(getQueryString("parentDlg"), 1);
        if (pApi != null) {
            pApi.zindex();
        }
    }
    api.close();
}
//关闭并刷新
function reloadDlg(refreshDsk){
    var api = frameElement.api;
    if(getQueryString("parentDlg")!=null && getQueryString("parentDlg")!='null' && getQueryString("parentDlg")!=''){
        var pApi = api.get(getQueryString("parentDlg"), 1);
        //alert(pApi + "-" + getQueryString("parentDlg"));
        if (pApi != null) {
            pW=pApi.content
            pApi.zindex();
            api.reload(pW,pW.location.href);
        }
        api.close();
    }
    else if(refreshDsk)
        api.reload();
    else
        api.close();
}
//function hideDlg(){
//    var api = frameElement.api;
//    if(getQueryString("parentDlg")!=null && getQueryString("parentDlg")!='null' && getQueryString("parentDlg")!=''){
//        var pApi=api.get(getQueryString("parentDlg"),1);
//        pApi.zindex();
//    }
//    api.hide();
//}
//显示窗口
function showDlg(dlgId){
    if(winDlg!=window && winDlg){
        var wApi=winDlg.get(dlgId,1);
        if(wApi!=null && wApi!='null' && wApi!='' && wApi!=undefined)
        {
            wApi.show();
            wApi.zindex();
        }    
    }    
}

function openChart(){
    winDlg=$.dialog({id:'Chart',title:'报表统计',content: 'url:Chart/DefaultChart.aspx',width:getWidth()*2/3,height:getHeight()-43,fixed:true,min:false}).max();        
}
function getCookie(objName){//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for(var i = 0;i < arrStr.length;i ++){
        var temp = arrStr[i].split("=");
        if(temp[0] == objName) return unescape(temp[1]);
    }
}
//清除缓存
function clearcache(type, path) {
    var url = "/clearcache.aspx?type=" + type + "&path=" + path;
    $.get(url, function(result) {
        alert("清除缓存成功！");
    });
}

//打开通知窗口
function openNoticeDlg(_content){
    $.dialog.notice = function( options ) 
    { 
        var opts = options || {}, 
            api, aConfig, hide, wrap, top, 
            duration = opts.duration || 800; 
             
        var config = { 
            id: 'Notice', 
            left: '100%', 
            top: '100%', 
            fixed: true, 
            drag: false, 
            resize: false,
            min:false,
            max:false,
            init: function(here){ 
                api = this; 
                aConfig = api.config; 
                wrap = api.DOM.wrap; 
                top = parseInt(wrap[0].style.top); 
                hide = top + wrap[0].offsetHeight; 
                             
                wrap.css('top', hide + 'px') 
                .animate({top: top + 'px'}, duration, function(){ 
                    opts.init && opts.init.call(api, here); 
                }); 
            }, 
            close: function(here){ 
                wrap.animate({top: hide + 'px'}, duration, function(){ 
                    opts.close && opts.close.call(this, here); 
                    aConfig.close = $.noop; 
                    api.close(); 
                }); 
                             
                return false; 
            } 
        }; 
             
        for(var i in opts) 
        { 
            if( config[i] === undefined ) config[i] = opts[i]; 
        } 
             
        return $.dialog( config ); 
    }; 

    $.dialog.notice({ 
        title: '信息提醒', 
        width: 230,  /*必须指定一个像素宽度值或者百分比，否则浏览器窗口改变可能导致lhgDialog收缩 */ 
        content: _content, 
        time: 8 
    });
}